package cn.wolfcode.crm.service.imp;


import cn.wolfcode.crm.domain.Supplier;
import cn.wolfcode.crm.mapper.SupplierMapper;
import cn.wolfcode.crm.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SupplierServiceImpl implements ISupplierService {
    @Autowired
    private SupplierMapper supplierMapper;
    @Override

    public void deleteByPrimaryKey(Long id) {
        if (id != null) {
            supplierMapper.deleteByPrimaryKey(id);
        }
    }

    @Override

    public void saveOrUpdate(Supplier supplier) {
        if (supplier.getId() != null) {
            //update
            supplierMapper.updateByPrimaryKey(supplier);
        }else {
            supplier.setCurrentdate(new Date());
            supplierMapper.insert(supplier);
        }
    }

    @Override
    public Supplier selectByPrimaryKey(Long id) {

            Supplier dept = supplierMapper.selectByPrimaryKey(id);
        return dept;

    }

    @Override
    public List<Supplier> selectAll() {
        List<Supplier> suppliers = supplierMapper.selectAll();
        return suppliers;
    }
}
